package com.cloud.generator.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.cloud.common.constant.GenConstants;
import com.cloud.domain.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * 业务表 gen_table
 *
 * @author yzj
 */
@Data
@Schema(name = "GenTable对象", description = "代码生成")
@TableName("gen_table")
public class GenTable extends BaseEntity {

    private static final long serialVersionUID = 1L;

    @Schema(description = "主键")
    @TableId(value = "table_id", type = IdType.AUTO)
    private Long tableId;

    @Schema(description = "表名称")
    private String tableName;

    @Schema(description = "表描述")
    private String tableComment;

    @Schema(description = "关联父表的表名")
    private String subTableName;

    @Schema(description = "本表关联父表的外键名")
    private String subTableFkName;

    @Schema(description = "表前缀名称(是否去除)")
    private String tablePrefix;

    @Schema(description = "实体类名称(首字母大写)")
    private String className;

    @Schema(description = "使用模板(crud单表操作 tree树表操作 sub主子表操作)")
    private String tplCategory;

    @Schema(description = "前端类型(element-ui模版)")
    private String tplWebType;

    @Schema(description = "生成包路径")
    private String packageName;

    @Schema(description = "生成模块名")
    private String moduleName;

    @Schema(description = "生成业务名")
    private String businessName;

    @Schema(description = "生成功能名")
    private String functionName;

    @Schema(description = "生成功能作者")
    private String functionAuthor;

    @Schema(description = "生成代码方式(0zip压缩包 1自定义路径)")
    private String genType;

    @Schema(description = "生成vue模块名")
    private String vueModuleName;

    @Schema(description = "vue项目工程路径")
    private String vueRoute;

    @Schema(description = "java项目工程路径")
    private String javaRoute;

    @Schema(description = "生成路径")
    private String genPath;

    @Schema(description = "上级菜单ID字段")
    private String parentMenuId;

    @Schema(description = "上级菜单名称字段")
    private String parentMenuName;

    @Schema(description = "树编码字段")
    private String treeCode;

    @Schema(description = "树父编码字段")
    private String treeParentCode;

    @Schema(description = "树名称字段")
    private String treeName;

    @Schema(description = "其它生成选项")
    private String options;

    @Schema(description = "主键信息")
    private GenTableColumn pkColumn;

    @Schema(description = "子表信息", hidden = true)
    private GenTable subTable;

    @Schema(description = "表列信息", hidden = true)
    private List<GenTableColumn> columns;

    @Schema(description = "备注说明")
    private String remark;

    public boolean isSub() {
        return isSub(this.tplCategory);
    }

    public static boolean isSub(String tplCategory) {
        return tplCategory != null && StringUtils.equals(GenConstants.TPL_SUB, tplCategory);
    }

    public boolean isTree() {
        return isTree(this.tplCategory);
    }

    public static boolean isTree(String tplCategory) {
        return tplCategory != null && StringUtils.equals(GenConstants.TPL_TREE, tplCategory);
    }

    public boolean isCrud() {
        return isCrud(this.tplCategory);
    }

    public static boolean isCrud(String tplCategory) {
        return tplCategory != null && StringUtils.equals(GenConstants.TPL_CRUD, tplCategory);
    }

}